/****************************************************************
 *  This file created by writerB.php on 03/26/2007 at 15:49:22  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: world.h
 *  Class Name: World
 *  Parent Classes: none
 *  Data members: 3
 *  Notes:
 ****************************************************************/

#ifndef __H_WORLD
#define __H_WORLD

#include <iostream>
#include <map>
#include <vector>
#include "board.h"
#include "combined.h"
#include "definitions.h"
#include "help.h"
#include "timer.h"
#include "timestamp.h"



class World {
	protected:
		// Protected data...
		bool						_exists;
		unsigned					_index;
		std::string					_version;
		std::string					_booted;
		std::map<std::string,Area*>			_areas;
		std::map<std::string,Character*>	_characters;
		std::multimap<std::string,Mob*>		_mobs;
		std::multimap<std::string,Object*>	_objects;
		std::vector< Timer* >		_timers;
		std::vector< Board* >		_boards;
		std::vector< std::string >	_banners;
		std::vector< Help* >		_helpList;
		unsigned long				_connects;
		fd_set						_fd_set;
		struct timeval				_tv;

		// Protected methods...
		void	load( void );
		void	loadServerData( void );
		void	loadAreas( void );
		void	loadTimers( void );
		void	loadHelp( void );
		void	loadBoards( void );
		void	loadBanners( void );
		void	saveCharacters( void );
		void	saveAreas( void );
		void	saveServerData( void );
		//void	saveBoards( void );
		void	flushOutput( void );
		void	updateCharacters( void );
		void	updateMobs( void );
		void	killFlaggedCharacters( void );
		void	handleInput( void );
		void	updateTimers( void );
		void	schedule( Timer* timer );
		bool	unschedule( Timer* timer );
		void			setConnects( unsigned long connects );
		unsigned long	getConnects( void );
		std::string connectionNumber2string( void );

	public:
		// Constructors...
		World();
		World( const World& );	// Doesn't change _WorldID
		~World();

		// Public accessor methods...
		void						setExists( const bool& exists );
		bool						getExists( void ) const;
		void						setIndex( const unsigned& index );
		unsigned					getIndex( void ) const;
		void						setVersion( const std::string& version );
		std::string					getVersion( void ) const;
		void						setBooted( const std::string& booted );
		std::string					getBooted( void ) const;
		std::map<std::string,Area* >&		getAreas( void );
		std::map<std::string,Character*>&	getCharacters( void );
		std::multimap<std::string,Mob*>&	getMobs( void );
		std::multimap<std::string,Object*>&	getObjects( void );
		std::vector< Timer* >&		getTimers( void );
		std::vector< Board* >&		getBoards( void );
		std::vector< Help* >&		getHelpList( void );
		std::vector< std::string >&	getBanners( void );

		// General methods...
		void	exist( const std::string& message, const int& port, const bool& copyover );
		void	monitor( void );
		void	copyover( void );
		void	copyoverRecovery( void );
		void	die( void );
		void	broadcast( const std::string& message );
		void	omninet( const std::string& message, Character* character = NULL, const bool& = false );
		void	save( void );

		Area*			add( Area* area );	// Push and return the given Area
		Area*			getArea( const std::string& keyword );		// Return the Area that matches keyword
		Area*			getParentArea( const unsigned& vnum );		// Return the Area that owns the given vnum
		bool			drop( Area* area );
		Room*			getRoom( const unsigned& vnum );			// Return the Room with the given vnum
		Character*		add( Character* character, bool newConnection = false );	// Push and return the given Character
		Character*		getCharacter( const std::string& name );	// Return the Character who matches name
		bool			dropCharacter( const std::string& name );	// Remove the Character who matches name
		bool			drop( Character* character );
		Mob*			add( Mob* mob );							// Push and return the given Mob
		Mob*			getMob( const std::string& name );			// Return the Mob who matches name
		bool			drop( Mob* mob );
		Object*			add( Object* object );						// Push and return the given Object
		Object*			getObject( const std::string& name );		// Return the first Object that matches name
		bool			drop( Object* object );
		Board*			addBoard( void );							// Push and return a new Board
		Help*			addHelp( void );							// Push and return the Help
		std::string		getHelp( const std::string& query, const unsigned& level = HEAD );	// Return the the Help text for the given query
		std::string		randomBanner( void );						// Return a random banner to send to a new connection

		// Statics...
		static World&	Instance( void );
};

// Our singleton instance...
inline World& World::Instance( void ) {
	static World _instance;
	return _instance;
}

// Associated operators...
std::ostream& operator << ( std::ostream&, const World& );
std::ostream& operator << ( std::ostream&, const World* );



#endif // __H_WORLD
